# -*- encoding=utf8 -*-
__author__ = "ZGD"
__title__ = "MTBF测试"

from airtest.core.api import *
import string
import random
from time import sleep

auto_setup(__file__)
init_device("Android", ime_method="ADBIME")


# device_name = "a39e9f8"
yosemite_activity = "com.netease.nie.yosemite"
tencent_activity = "com.tencent.wemeet.app"
wps_activity = "cn.wps.moffice_eng"
conferenceassistant_activity = "com.android.dpconferenceassistant"
intelligence_activity = "com.duoping.intelligence.assistant"
chrome_activity = "com.android.chrome"
pdf_reader_activity = "com.duoping.reader"
setting_activity = "com.android.settings"
gallery_activity= "com.android.gallery3"
documentsui_activity= "com.android.documentsui"
aiqiyi_activity = "com.qiyi.video.pad"

tiktok_cycle_num = 40 


def reboot_device():
    sleep(2)
    out = os.popen("adb reboot").read() 
    sleep(60*2)
    #shell(f"adb -s {device_name}  wait-for-device")
    connect_device(f"android://127.0.0.1:5037/{device_name}")
    sleep(10)
    print("重新连接成功")
    
def kill_activity():
    try:
        start_app(setting_activity)
        sleep(2)
        if exists(Template(r"tpl1699499537821.png", record_pos=(-0.044, 0.035), resolution=(1920, 1200))):
            touch((1732,999))

        for i in range(20):
            out = os.popen("adb shell dumpsys window | findstr mCurrentFocus").read()
            activity_str = out.split("u0")[1].split("/")[0]
            print("activity_str---", activity_str)
            if "allApp" in activity_str:
                print("清理应用程序完毕")
                break
            os.popen(f"adb shell am force-stop {activity_str}").read()
            time.sleep(2)
    except:pass
    print("清除多余应用进程")

    
class TestMtbf:
    try:
        uninstall(yosemite_activity)
    except:pass
    sleep(2)
    kill_activity()
    def test_tencent(self):
        print("开始打开腾讯会议进行视频会议5分钟")
        try:
            start_app(tencent_activity)
            sleep(4)
#             stop_app(intelligence_activity)
            touch(Template(r"tpl1699519603743.png", record_pos=(-0.001, 0.181), resolution=(1920, 1200)))
            sleep(4)
            
            touch(Template(r"tpl1699519648748.png", record_pos=(-0.139, 0.243), resolution=(1920, 1200)))
            sleep(2)
            ST.SAVE_IMAGE = False
            sleep(4)
            if exists(Template(r"tpl1699501089264.png", record_pos=(-0.326, 0.032), resolution=(1920, 1200))):
                touch(Template(r"tpl1699501089264.png", record_pos=(-0.326, 0.032), resolution=(1920, 1200)))
            sleep(2)
            if exists(Template(r"tpl1690800137439.png", record_pos=(-0.188, -0.017), resolution=(1920, 1200))):
                touch(Template(r"tpl1690800137439.png", record_pos=(-0.188, -0.017), resolution=(1920, 1200)))
            sleep(3)
            if exists(Template(r"tpl1690370005165.png", record_pos=(-0.186, 0.075), resolution=(1920, 1200))):
                sleep(1)
                touch(Template(r"tpl1690370005165.png", record_pos=(-0.186, 0.075), resolution=(1920, 1200)))
            time.sleep(4)
            try:
                touch(Template(r"tpl1694001742305.png", record_pos=(-0.068, -0.14), resolution=(1920, 1200)))
            except:
                touch(Template(r"tpl1694087339553.png", record_pos=(-0.071, -0.156), resolution=(1920, 1200)))
            
            time.sleep(4)

            touch(Template(r"tpl1689821937629.png", record_pos=(-0.147, 0.151), resolution=(1920, 1200)))
            time.sleep(4)
            
            if exists(Template(r"tpl1690800206710.png", record_pos=(-0.113, -0.004), resolution=(1920, 1200))):
                touch(Template(r"tpl1690800206710.png", record_pos=(-0.113, -0.004), resolution=(1920, 1200)))
            
            
            ST.SAVE_IMAGE = True

            time.sleep(5)
            
            touch(Template(r"tpl1689822090985.png", record_pos=(-0.256, 0.166), resolution=(1920, 1200)))

            sleep(2)
            for i  in range(30):
                if exists(Template(r"tpl1697082757698.png", record_pos=(-0.001, 0.004), resolution=(1920, 1200))):
                    touch(Template(r"tpl1697082757698.png", record_pos=(-0.001, 0.004), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1699519884387.png", record_pos=(-0.004, 0.027), resolution=(1920, 1200))):
                    touch(Template(r"tpl1699519884387.png", record_pos=(-0.004, 0.027), resolution=(1920, 1200)))
                                
                sleep(2)
                if exists(Template(r"tpl1699519990079.png", record_pos=(0.067, -0.091), resolution=(1920, 1200))):
                    touch(Template(r"tpl1699519990079.png", record_pos=(0.067, -0.091), resolution=(1920, 1200)))

                    sleep(.5)
                time.sleep(1)
                print("视频会议等待中，请稍后")
            sleep(3)

            touch(Template(r"tpl1689822112401.png", record_pos=(-0.256, 0.167), resolution=(1920, 1200)))

            print("5分钟的会议视频结束了")
            sleep(2)
            touch(Template(r"tpl1693305597643.png", record_pos=(-0.001, 0.193), resolution=(1920, 1200)))

            sleep(4)
            touch(Template(r"tpl1693305678785.png", record_pos=(0.0, 0.163), resolution=(1920, 1200)))
            
            sleep(4)
            assert_exists(Template(r"tpl1699501492416.png", record_pos=(0.25, -0.203), resolution=(1920, 1200)), "是否进入共享白板界面")
            sleep(2)
            ST.SAVE_IMAGE = False
            for i in range(30):
                if not exists(Template(r"tpl1690887311537.png", record_pos=(-0.207, 0.164), resolution=(1920, 1200))):
                    assert False
                    sleep(2)
                
                sw_list = [(190,305),(396,258),(382,677),
                           (812,739),(1010,549),(1056,270)]
                swipe(random.choice(sw_list),random.choice(sw_list))
                sleep(4)
            ST.SAVE_IMAGE = True
            swipe(random.choice(sw_list),random.choice(sw_list))
            sleep(3)
            ST.SAVE_IMAGE = True

            touch(Template(r"tpl1690887366505.png", record_pos=(0.101, -0.219), resolution=(1920, 1200)))
            sleep(5)
            
            print("准备共享屏幕")
            touch(Template(r"tpl1693305597643.png", record_pos=(-0.001, 0.193), resolution=(1920, 1200)))
            sleep(2)
            touch(Template(r"tpl1697702508973.png", record_pos=(0.0, 0.13), resolution=(1920, 1200)))
            sleep(8)
            assert_exists(Template(r"tpl1699501600190.png", record_pos=(-0.001, 0.185), resolution=(1920, 1200)), "断言是否正常共享桌面")

            for i  in range(30):
                time.sleep(1)
                print("会议画面等待中，请稍后")
                        
            sleep(5)
            touch(Template(r"tpl1699501600190.png", record_pos=(-0.001, 0.185), resolution=(1920, 1200)))
            sleep(3)
            try:
                touch(Template(r"tpl1690369962551.png", record_pos=(0.113, -0.223), resolution=(1920, 1200)))
            except:
                touch(Template(r"tpl1690800285907.png", record_pos=(0.112, -0.224), resolution=(1920, 1200)))

            sleep(3)
            touch(Template(r"tpl1690369981684.png", record_pos=(-0.144, 0.133), resolution=(1920, 1200)))
            sleep(3)
            if exists(Template(r"tpl1690370005165.png", record_pos=(-0.186, 0.075), resolution=(1920, 1200))):
                sleep(1)
                touch(Template(r"tpl1690370005165.png", record_pos=(-0.186, 0.075), resolution=(1920, 1200)))
            sleep(4)
        except:pass
        finally:
            stop_app(tencent_activity)
            sleep(1)
            stop_app(conferenceassistant_activity)
            sleep(1)
        print("结束腾讯会议进行视频会议5分钟")
        
    def test_start_wps_work(self):
        sleep(3)
        print("开始使用wps编辑PPT word excel文档10分钟")
        try:
            start_app(wps_activity)
            time.sleep(5)
            try:
                if exists(Template(r"tpl1690439599052.png", record_pos=(-0.002, 0.122), resolution=(1920, 1200))):
                    touch(Template(r"tpl1690439599052.png", record_pos=(-0.002, 0.122), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1690439651891.png", record_pos=(-0.261, -0.219), resolution=(1920, 1200))):
                    touch(Template(r"tpl1690439651891.png", record_pos=(-0.261, -0.219), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1689835994001.png", record_pos=(0.091, -0.251), resolution=(1920, 1200))):
                    touch(Template(r"tpl1689835994001.png", record_pos=(0.091, -0.251), resolution=(1920, 1200)))
            except:pass
            touch(Template(r"tpl1690800692855.png", record_pos=(-0.258, -0.036), resolution=(1920, 1200)))

            sleep(5)
            touch(Template(r"tpl1690800730354.png", record_pos=(-0.177, -0.072), resolution=(1920, 1200)))

            sleep(5)
            touch(Template(r"tpl1689835669941.png", record_pos=(-0.215, -0.174), resolution=(1920, 1200)))
            sleep(5)
            
            if exists(Template(r"tpl1699521650178.png", record_pos=(-0.002, 0.026), resolution=(1920, 1200))):
                touch(Template(r"tpl1699521650178.png", record_pos=(-0.002, 0.026), resolution=(1920, 1200)))

            #点击输入栏输入文本
            touch((958,309))
            sleep(3)
            ST.SAVE_IMAGE = False
            import random,string
            for i in range(20):
                str = random.choice(string.ascii_letters)
#                 text(str,enter=False)
                shell(f"input text {str}")
                sleep(2)
            print("输入文本完毕")
            ST.SAVE_IMAGE = True
            sleep(2)
            touch(Template(r"tpl1690286740065.png", record_pos=(-0.257, -0.211), resolution=(1920, 1200)))
            sleep(3)
            touch(Template(r"tpl1690286783441.png", record_pos=(0.044, -0.016), resolution=(1920, 1200)))
            sleep(5)
            touch(Template(r"tpl1690800875793.png", record_pos=(-0.263, -0.214), resolution=(1920, 1200)))

        except:pass
        finally:
            stop_app(wps_activity)
        sleep(5)
        print("结束使用wps编辑PPT word excel文档10分钟")
        
    def test_start_chrome_word(self):
#         kill_activity()
        sleep(3)
        print("开始打开浏览器进行内容搜索网页随机浏览10分钟")
        """
        chrome网页浏览器，浏览十分钟
        """
        try:
            start_app(chrome_activity)
            for i in range(2):
                ST.SAVE_IMAGE = False
                if exists(Template(r"tpl1691064584266.png", record_pos=(0.096, -0.029), resolution=(1920, 1200))):
                    touch(Template(r"tpl1691064584266.png", record_pos=(0.096, -0.029), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1691064615408.png", record_pos=(-0.003, 0.119), resolution=(1920, 1200))):
                    touch(Template(r"tpl1691064615408.png", record_pos=(-0.003, 0.119), resolution=(1920, 1200)))
                sleep(3)
                if exists(Template(r"tpl1694418550159.png", record_pos=(0.068, 0.187), resolution=(1920, 1200))):
                    touch(Template(r"tpl1694418550159.png", record_pos=(0.068, 0.187), resolution=(1920, 1200)))
                sleep(3)                    
                if exists(Template(r"tpl1694418666147.png", record_pos=(0.061, 0.092), resolution=(1920, 1200))):
                    touch(Template(r"tpl1694418666147.png", record_pos=(0.061, 0.092), resolution=(1920, 1200)))


            sleep(4)
            #点击地址栏
            ST.SAVE_IMAGE = True
            touch((908,258))
            sleep(4)
            #text("https://news.baidu.com/")
            #text("https://new.qq.com/",enter=True)
            #shell("input text 'https://new.qq.com/'")
            shell("input text 'https://new.qq.com/'")
            sleep(4)
            shell ("input keyevent '66'")
            sleep(5)
            ST.SAVE_IMAGE = False
            #滑动新闻页
            cycle_num = 150
            num = 500
            for i in range(cycle_num):
                swipe((num,650),(num,300),duration=0.1,steps=3)
                sleep(2)

            sleep(2)
            for i in range(cycle_num):
                swipe((num,300),(num,650),duration=0.1,steps=3)
                sleep(2)
            print("chrome浏览器浏览网页完毕")
            sleep(5) 
            ST.SAVE_IMAGE = True
            sleep(3)
            swipe((num,300),(num,650),duration=0.1,steps=3)
        except:pass
        finally:
            stop_app(chrome_activity)
        print("结束打开浏览器进行内容搜索网页随机浏览10分钟")
        
    def test_start_wechat(self):
        """
        打开微信聊天10s
        """
        pass
    
    def test_start_tiktok(self):
#         kill_activity()
        sleep(3)
        print("开始打开抖音进行短视频观看2分钟")
        """
        打开抖音观看视频2分钟
        """
        try:
            start_app("com.ss.android.ugc.aweme")
            sleep(5)
            for i in range(2):
                
                if exists(Template(r"tpl1690801118885.png", record_pos=(-0.038, 0.04), resolution=(1920, 1200))):
                    touch(Template(r"tpl1690801118885.png", record_pos=(-0.038, 0.04), resolution=(1920, 1200)))

                sleep(2)
                if exists(Template(r"tpl1689843527245.png", record_pos=(-0.001, 0.06), resolution=(1920, 1200))):
                    touch(Template(r"tpl1689843527245.png", record_pos=(-0.001, 0.06), resolution=(1920, 1200)))
                sleep(1)
                if exists(Template(r"tpl1689843724839.png", record_pos=(-0.039, 0.034), resolution=(1920, 1200))):
                    touch(Template(r"tpl1689843724839.png", record_pos=(-0.039, 0.034), resolution=(1920, 1200)))
                sleep(2)    
                if exists(Template(r"tpl1694421241743.png", record_pos=(-0.002, 0.02), resolution=(1920, 1200))):
                    touch(Template(r"tpl1694421241743.png", record_pos=(-0.002, 0.02), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1693367979601.png", record_pos=(-0.001, 0.011), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693367979601.png", record_pos=(-0.001, 0.011), resolution=(1920, 1200)))

                sleep(1)
                if exists(Template(r"tpl1689844169306.png", record_pos=(0.257, -0.027), resolution=(1920, 1200))):
                    touch(Template(r"tpl1689844169306.png", record_pos=(0.257, -0.027), resolution=(1920, 1200)))
                sleep(1)
                if exists(Template(r"tpl1693568509778.png", record_pos=(-0.261, -0.198), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693568509778.png", record_pos=(-0.261, -0.198), resolution=(1920, 1200)))

                sleep(1)
                if exists(Template(r"tpl1693225378871.png", record_pos=(0.0, 0.01), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693225378871.png", record_pos=(0.0, 0.01), resolution=(1920, 1200)))


            sleep(2)
            num = 1000
            time_list = [2,3,4,5,6,7,8,9]
            ST.SAVE_IMAGE = False
            for i in range(tiktok_cycle_num):
                a_ime = random.choice(time_list)
                swipe((num,738),(num,372),duration=0.1)           
                sleep(a_ime)
                if exists(Template(r"tpl1689843724839.png", record_pos=(-0.039, 0.034), resolution=(1920, 1200))):
                    sleep(1)
                    touch(Template(r"tpl1689843724839.png", record_pos=(-0.039, 0.034), resolution=(1920, 1200)))
                    sleep(.5) 
                if exists(Template(r"tpl1693568509778.png", record_pos=(-0.261, -0.198), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693568509778.png", record_pos=(-0.261, -0.198), resolution=(1920, 1200)))
                sleep(.5)
                if exists(Template(r"tpl1693225331932.png", record_pos=(-0.001, 0.009), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693225331932.png", record_pos=(-0.001, 0.009), resolution=(1920, 1200)))
                sleep(.5)
                
                if exists(Template(r"tpl1694421426111.png", record_pos=(-0.005, 0.004), resolution=(1920, 1200))):
                    touch(Template(r"tpl1694421426111.png", record_pos=(-0.005, 0.004), resolution=(1920, 1200)))
                sleep(2)
                if exists(Template(r"tpl1693225627632.png", record_pos=(-0.001, -0.004), resolution=(1920, 1200))):
                    touch(Template(r"tpl1693225627632.png", record_pos=(-0.001, -0.004), resolution=(1920, 1200)))
                sleep(2)                    
                if exists(Template(r"tpl1694421482420.png", record_pos=(0.161, 0.124), resolution=(1920, 1200))):
                    touch(Template(r"tpl1694421482420.png", record_pos=(0.161, 0.124), resolution=(1920, 1200)))

            
            ST.SAVE_IMAGE = True
            swipe((num,738),(num,372),duration=0.1)           
            print("观看完毕")
            sleep(3)
        except:pass
        finally:
            stop_app("com.ss.android.ugc.aweme")
        print("结束打开抖音进行短视频观看2分钟")
    
    def test_control_center(self):
#         try:
#         except:pass
#         finally:
        pass

    def test_start_pdf_reader(self):
        #pdf阅读
        
        try:
            start_app(pdf_reader_activity)
            sleep(3)
            touch((567,382))
            sleep(3)
            #缩放pdf
            for i in range(30):
                for i in range(5):
                    swipe((990,737),(990,386))
                sleep(1)
                assert_exists(Template(r"tpl1700219445543.png", record_pos=(-0.001, 0.152), resolution=(1920, 1200)), "正常进入pdf内容页面")
                sleep(1)
                pinch(in_or_out='in', center=None, percent=0.3)
                sleep(1)
                for i in range(2):
                    pinch(in_or_out='out', center=None, percent=0.3)
                
                touch(Template(r"tpl1700218968416.png", record_pos=(-0.084, 0.15), resolution=(1920, 1200)))
                sleep(2)
                for i in range(2):
                    swipe((990,386),(990,737))
                touch(Template(r"tpl1700219106021.png", record_pos=(-0.084, 0.151), resolution=(1920, 1200)))
                sleep(1)
                pinch(in_or_out='in', center=None, percent=0.3)
                sleep(1)
                for i in range(2):
                    pinch(in_or_out='out', center=None, percent=0.3)

                sleep(2)
                touch(Template(r"tpl1700219196977.png", record_pos=(-0.019, 0.15), resolution=(1920, 1200)))
                sleep(2)
                for i in range(2):
                    swipe((990,737),(990,386))
                
                touch(Template(r"tpl1700219258053.png", record_pos=(0.014, 0.151), resolution=(1920, 1200)))
                sleep(2)
                
                touch(Template(r"tpl1700219600206.png", record_pos=(-0.018, 0.149), resolution=(1920, 1200)))

                
        except Exception as e:
            raise e
        finally:
            stop_app(pdf_reader_activity)

    def test_start_gallery(self):
        #图库
#         kill_activity()
        try:
            start_app(gallery_activity)                     
            sleep(2)
            assert_exists(Template(r"tpl1700220555817.png", record_pos=(-0.233, -0.189), resolution=(1920, 1200)), "成功进入图库")
            sleep(2)
            touch((800,377))
            sleep(2)
            for i in range(10):
                for i in range(8):
                    touch(Template(r"tpl1704770210983.png", record_pos=(0.012, 0.152), resolution=(1920, 1200)))
                    sleep(1)
                    
                for i in range(3):
                    touch(Template(r"tpl1704770265564.png", record_pos=(-0.017, 0.153), resolution=(1920, 1200)))

                    sleep(1)

                for i in range(5):
                    pinch(in_or_out='out', center=None, percent=0.3)
                    sleep(1)
                    for i in range(2):
                        pinch(in_or_out='in', center=None, percent=0.3)

                for i in range(10):
                    touch(Template(r"tpl1700221003556.png", record_pos=(-0.047, 0.151), resolution=(1920, 1200)))
                    sleep(1)
                    touch(Template(r"tpl1700221083400.png", record_pos=(0.043, 0.151), resolution=(1920, 1200)))
                    sleep(2)

            ST.SAVE_IMAGE = True
        except:pass
        finally:
            stop_app(gallery_activity)            

    def test_start_documentsui(self):
        #文件
#         kill_activity()
        try:
            start_app(documentsui_activity)
            sleep(3)
            for i in range(5):
                ST.SAVE_IMAGE = False

                touch(Template(r"tpl1693470270889.png", record_pos=(-0.246, -0.128), resolution=(1920, 1200)))
                sleep(3)
                assert_exists(Template(r"tpl1693471435869.png", record_pos=(-0.126, -0.166), resolution=(1920, 1200)), "断言图片按钮展示")
                sleep(3)
                touch(Template(r"tpl1693474742286.png", record_pos=(-0.106, -0.081), resolution=(1920, 1200)))
                
                sleep(3)
                touch(Template(r"tpl1693470294332.png", record_pos=(-0.246, -0.101), resolution=(1920, 1200)))
                sleep(3)
                touch(Template(r"tpl1693470306092.png", record_pos=(-0.249, -0.07), resolution=(1920, 1200)))
                sleep(3)
                touch(Template(r"tpl1693470323520.png", record_pos=(-0.248, -0.043), resolution=(1920, 1200)))
                sleep(3)
                touch(Template(r"tpl1693470344598.png", record_pos=(-0.246, -0.011), resolution=(1920, 1200)))
                assert_exists(Template(r"tpl1693471392592.png", record_pos=(-0.124, -0.165), resolution=(1920, 1200)), "断言下载按钮展示")

                sleep(3)

        except:pass
            
        finally:
            stop_app(documentsui_activity)
            
    def test_aiqiyi(self):
        #爱奇艺
#         kill_activity()
        try:
            start_app(aiqiyi_activity)
            sleep(5)
            ST.SAVE_IMAGE = False
            if exists(Template(r"tpl1693562253460.png", record_pos=(0.036, 0.086), resolution=(1920, 1200))):
                touch(Template(r"tpl1693562253460.png", record_pos=(0.036, 0.086), resolution=(1920, 1200)))
            sleep(3)
            if exists(Template(r"tpl1693562324064.png", record_pos=(0.227, -0.184), resolution=(1920, 1200))):
                touch(Template(r"tpl1693562324064.png", record_pos=(0.227, -0.184), resolution=(1920, 1200)))
            sleep(3)
            num_start = 956   
            for i in range(10):
                swipe((num_start,828),(num_start,500))
                sleep(.5)
            sleep(2)
            for i in range(10):
                swipe((num_start,500),(num_start,828))
                sleep(.5)
            sleep(3)
            ST.SAVE_IMAGE = True
            assert_exists(Template(r"tpl1693563861089.png", record_pos=(0.22, 0.195), resolution=(1920, 1200)), "断言爱奇艺正常运行")
            sleep(3)
            touch((884,798))
            sleep(200)
        except:pass
        finally:
            stop_app(aiqiyi_activity)
    
    def test_switch_navigation_bar_all_app(self):
        """
        切换导航栏所有的app
        """
        try:
            sleep(1)
            
            for i in range(15):
                try:
                    touch(Template(r"tpl1704772140519.png", record_pos=(-0.061, 0.134), resolution=(1920, 1200)))
                    sleep(2)

                except:pass
                assert_exists(Template(r"tpl1704801022869.png", record_pos=(0.163, 0.244), resolution=(1920, 1200)), "正常进入dock")
                ST.SAVE_IMAGE = False
                touch(Template(r"tpl1704772163408.png", record_pos=(-0.165, 0.243), resolution=(1920, 1200)))
                sleep(1)
                touch(Template(r"tpl1704772182413.png", record_pos=(-0.12, 0.245), resolution=(1920, 1200)))
                sleep(1)
                touch(Template(r"tpl1704772206446.png", record_pos=(-0.052, 0.244), resolution=(1920, 1200)))
                sleep(1)
                touch(Template(r"tpl1704772220955.png", record_pos=(-0.006, 0.242), resolution=(1920, 1200)))
                sleep(1)
                touch(Template(r"tpl1704772238595.png", record_pos=(0.041, 0.245), resolution=(1920, 1200)))
                sleep(1)
                touch(Template(r"tpl1704772258362.png", record_pos=(0.087, 0.244), resolution=(1920, 1200)))
                sleep(2)
                touch(Template(r"tpl1704799035238.png", record_pos=(0.223, 0.258), resolution=(1920, 1200)))
                sleep(2)
                home()
            ST.SAVE_IMAGE = False
        except:pass
        finally:
            kill_activity()

    
    def test_inair_app_long_click_swipe(self):
        #inair滑动 需要 选择好颈环和phone 设备信息
        
        phone_name = "YNC0223303000669"
        collar_name = "34558cb0"
        phone = connect_device(f"Android://127.0.0.1:5037/{phone_name}") 
        set_current(phone_name)        
#         wake()
        width, height = phone.get_current_resolution()
        k = (300, 1000)
        g = (500, 2000)
        for i in range(10):
            ST.SAVE_IMAGE = False                        
            all_list = []
            for i in range(random.randint(2,10)):
                star_num = random.randint(k[0], k[1])
                end_num = random.randint(g[0], g[1])
                all_list.append((star_num,end_num))
            phone.minitouch.swipe_along(all_list,duration=random.choice((.5,1,3,5)))
            sleep(2)
            touch((star_num,end_num))
            sleep(2)
        assert_exists(Template(r"tpl1694522224351.png", record_pos=(0.284, 0.73), resolution=(1220, 2700)), "还在触控板页面")
        sleep(2)
        ST.SAVE_IMAGE = True                
        phone.minitouch.swipe_along(all_list)
        sleep(2)
        collar = connect_device(f"Android://127.0.0.1:5037/{collar_name}") 
        set_current(collar_name)        
            
    def run_get_report(self):
        a = 1 
        while a<500:
            self.test_tencent()
            self.test_start_wps_work()
            self.test_start_chrome_word()
            self.test_start_tiktok()
#             self.test_control_center()
#             self.test_open_close_wifi()
#             self.test_open_close_bluetooth()
            self.test_start_gallery()
            self.test_start_documentsui()
#             self.test_inair_app_long_click_swipe()
            self.test_switch_navigation_bar_all_app()
    
            sleep(10)
            from airtest.report.report import simple_report
            simple_report(__file__,logpath=True,output="log"+str(a)+".html")
            a = a+1
            
    def test_debug_code(self):
#         self.test_tencent()
#         self.test_start_wps_work()
#         self.test_start_chrome_word()
#         self.test_start_tiktok()
#         self.test_control_center()
#         self.test_start_pdf_reader()
#         self.test_start_gallery()
#         self.test_start_documentsui()
#         self.test_aiqiyi()
#         self.test_switch_navigation_bar_app()
#         self.test_inair_app_long_click_swipe()
        self.test_switch_navigation_bar_all_app()

    
if __name__=="__main__":
    tm = TestMtbf()
#     tm.test_debug_code()
    tm.run_get_report()
